<template>
	<view class="content">
		<view class="top_nav">
			<view class="navcont">
				<view :class="navType == item.type ? 'nav' : ''" v-for="(item,index) in navlist" :key="index" @click="tapnav(item)">{{item.name}}</view>
			</view>
		</view>
		<view class="group">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">	
				<view class="list" v-for="(item,index) in buyBillList" :key="index" @click="goOrder(item)">
					<view class="list_fl">
						<image class="list_pic" :src="item.image" mode="aspectFill"></image>
					</view>
					<view class="list_fr">
						<view class="list_name ellipsis_2">{{item.productName}}</view>
						<view class="list_price">
							<view class="sign iconfont">&#xe604;</view>
							<view class="price">{{item.price}}</view>
						</view>
					</view>
				</view>
			</mescroll-body>
				
		</view>
		
		
	</view>
</template>

<script>
	import api from "../../../../../common/api/api.js"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				navlist:[{type:1,name:'交易完成'},{type:2,name:'转拍完成'}],
				navType:1,
				downOption: {
					auto: true //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					auto: true, // 不自动加载
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '~ 空空如也 ~', // 提示
						btnText: '刷新',
						// 列表第一页无任何数据时,显示的空布局
						// use : 是否启用
						// icon : 空布局的图标路径 (支持网络路径)
						// tip : 提示文本
						// btnText : 按钮文本
						// fixed : 是否使用定位,默认false; 配置fixed为true,以下的top和zIndex才生效 (transform会使fixed失效,所以最终还是会降级为absolute)
						// top : fixed定位的top值 (完整的单位值,如"100rpx", "10%";)
						// zIndex : fixed定位z-index值
					},
					textNoMore: "--我也是有底线的--" //没有更多数据的提示文本
				},
				list:[],
				buyBillList:[]
			}
		},
		onLoad(options) {
			console.log(options)
			let that = this;
			if (Object.keys(options).length != 0) {
				that.navType = options.navType
			}
			
			
			uni.$on('billOrder',function(data){
			    console.log('监听到事件来自 update ，携带参数 msg 为：' + data.msg);
				that.mescroll.resetUpScroll(); //调用加载
			})
		},
		methods: {
			// 选择
			tapnav: function (item) {
				this.navType = item.type;
				this.mescroll.resetUpScroll(); //调用加载
			},
			downCallback(){
				this.mescroll.resetUpScroll(); //调用加载
			},
			upCallback(page) {
				//联网加载数据
				console.log(page)
				let that = this;
				api.userPayBillHistory(that.navType,{
					page:page.num,
					limit:page.size
				}).then(res => {
					console.log(res,"===")
					let curPageData =res.data.records;
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length;
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = res.data.pages;
					//设置列表数据
					setTimeout(() => { // 模拟效果
						if (page.num == 1) this.buyBillList = []; //如果是第一页需手动置空列表
						this.buyBillList = this.buyBillList.concat(curPageData); //追加新数据
						console.log(this.buyBillList,"地址信息");
						// 请求成功,隐藏加载状态
						//方法一(推荐): 后台接口有返回列表的总页数 totalPage
						this.mescroll.endByPage(curPageLen, totalPage);
					}, 500)
					
				}).catch(err => {
					that.mescroll.endErr()
				})
				
			},
			// 详情页
			goOrder: function (item) {
				uni.navigateTo({
					url: '../historyDetail/historyDetail?id=' + item.id,
				});
			}
			
			
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: 'userHistoryOrder/userHistoryOrder',
			});
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		letter-spacing: 3rpx;
		background: #F5F5F5;
		font-family: 'PingFang SC';
		font-size: 28rpx;
		color: #212121;
	}
	.content {
		width: 100%;
		box-sizing: border-box;
	}
	.top_nav {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 10rpx 50rpx;
		position: sticky;
		top: 0rpx;
		left: 0;
		z-index: 999;
		.navcont {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: 28rpx;
			color: #666666;
			height: 80rpx;
			line-height: 80rpx;
			.nav {
				color: #212121;
				position: relative;
				&::after {
					content: "";
					width: 80rpx;
					height: 6rpx;
					background: #E42221;
					border-radius: 3rpx;
					position: absolute;
					left: 0;
					right: 0;
					bottom: 0;
					margin: auto;
					z-index: 10;
				}
			}
			
		}
		
	}
	
	.group {
		width: 96%;
		box-sizing: border-box;
		margin: 20rpx auto 0 auto;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 0 0;
		padding: 0 20rpx;
		.list {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx 0 30rpx 0;
			border-bottom: 2rpx solid #F5F5F5;
			display: flex;
			justify-content: flex-start;
			.list_fl {
				width: 190rpx;
				height: 190rpx;
				.list_pic {
					width: 100%;
					height: 100%;
					border-radius: 8rpx;
				}
			}
			.list_fr {
				width: calc(100% - 190rpx);
				box-sizing: border-box;
				padding-left: 30rpx;
				display:flex;
				flex-flow: column; //垂直排列
				justify-content: space-between;//两端对齐
				.list_price {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					font-size: 36rpx;
					color: #E42221;
					.sign {
						font-size: 32rpx;
						color: #FFDA71;
					}
				}
			}
		}
		
		
	}
	

</style>
